using System;
using Actions;
using Events;
using UnityEngine;

namespace Globals.States
{
    public class GameStartedState : MonoBehaviour, IState
    {
        [SerializeField] private VoidEventChannel gameStartedEvent;
        [SerializeField] private Ring ring;
        [SerializeField] private Animator pauseUi;

        [SerializeField] private GameObject scoreText;
        
        private static readonly int ShowBottom = Animator.StringToHash("ShowBottom");


        private void Awake()
        {
            scoreText.SetActive(false);
            
            gameStartedEvent.Init();
        }

        public void Enter()
        {
            ring.ShrunkToMinSize += Ring_ShrunkToMinSize;
            
            pauseUi.SetTrigger(ShowBottom);

            scoreText.SetActive(true);
            
            gameStartedEvent.Raise();
        }

        public void OnUpdate()
        {
        }

        public void Exit()
        {
            ring.ShrunkToMinSize -= Ring_ShrunkToMinSize;
        }
        
        private void Ring_ShrunkToMinSize()
        {
            GameState.Instance.SwitchState(typeof(GameOverState));
        }
    }
}
